package com.ywyself.controller.handler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jfinal.handler.Handler;
import com.ywyself.common.YsConfig;
import com.ywyself.common.pool.DataPool;
import com.ywyself.ext.kit.YsHandlerKit;
import com.ywyself.ext.utils.YsStringUtils;
import com.ywyself.model.Option;

public class SiteAccessHandler extends Handler {

    @Override
    public void handle(String target, HttpServletRequest request, HttpServletResponse response, boolean[] isHandled) {
        if (target.contains(".") || target.contains(YsConfig.ADMIN_URL)) {
            // 白名单：样式，管理后台，验证码
            next.handle(target, request, response, isHandled);
        } else if (!YsStringUtils.isEqual(DataPool.getSiteStatus(), Option.STATUS_OPEN)) {
            YsHandlerKit.renderView("/promptPage/site_closed.html", request, response, isHandled);
        } else {
            next.handle(target, request, response, isHandled);
        }
    }

}
